from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Enum, Text, Date, Numeric
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.core.database import Base
import enum

class ChangeOrderStatus(str, enum.Enum):
    PENDING = "pending"
    APPROVED = "approved"
    REJECTED = "rejected"

class ChangeOrder(Base):
    __tablename__ = "change_orders"
    
    id = Column(Integer, primary_key=True, index=True)
    project_id = Column(Integer, ForeignKey("projects.id"), nullable=False, index=True)
    change_number = Column(String(50), unique=True, nullable=False, index=True)
    change_date = Column(Date, nullable=False)
    change_content = Column(Text, nullable=False)
    change_amount = Column(Numeric(12, 2), nullable=False)
    status = Column(Enum(ChangeOrderStatus), default=ChangeOrderStatus.PENDING, nullable=False)
    applicant = Column(String(50), nullable=True)
    approver = Column(String(50), nullable=True)
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
    
    project = relationship("Project", back_populates="change_orders")

